﻿using Nortec.Security.BusinessComponents;
using Nortec.Security.BusinessEntities;

namespace Nortec.Security
{
    public class Privilegios
    {
        public static string AnularOT
        {
            get
            {
                return "Anular Orden de Trabajo";
            }
        }
        public static string TerminarOT
        {
            get
            {
                return "Terminar Orden de Trabajo";
            }
        }

        public static string IngresarDatos
        {
            get
            {
                return "Ingresar gastos";
            }
        }

        public static string EditarOTEnProceso
        {
            get
            {
                return "Editar OT En Proceso";
            }
        }

        public static string VerOT
        {
            get
            {
                return "Ver OT completa";
            }
        }
    }
    public class NortecMembership
    {
        #region Declarations
        private static int applicationId;
        private static string applicationName;
        private static int companyId;
        private static string companyName;
        private static int branchId;
        private static string branchName;
        private static NortecPrincipal principal;
        private static NortecIdentity identity;
        
        public static NortecPrincipal Principal
        {
            get
            {
                return principal;
            }
            set
            {
                principal = value;
            }
        }
        public static NortecIdentity Identity
        {
            get
            {
                return identity;
            }
            set
            {
                identity = value;
            }
        }
        public static int ApplicationId
        {
            get
            {
                return applicationId;
            }
            set
            {
                applicationId = value;
            }
        }
        public static string ApplicationName
        {
            get
            {
                return applicationName;
            }
            set
            {
                applicationName = value;
            }
        }
        public static int CompanyId
        {
            get
            {
                return companyId;
            }
            set
            {
                companyId = value;
            }
        }
        public static string CompanyName
        {
            get
            {
                return companyName;
            }
            set
            {
                companyName = value;
            }
        }
        public static int BranchId
        {
            get
            {
                return branchId;
            }
            set
            {
                branchId = value;
            }
        }
        public static string BranchName
        {
            get
            {
                return branchName;
            }
            set
            {
                branchName = value;
            }
        }
        #endregion

        #region Methods:Public
        public static void Initialize(int companyId, string companyName, int branchId, string branchName, string applicationName)
        {
            var securityObject = new BCSecurity();
            CompanyId = companyId;
            CompanyName = companyName;

            BranchId = branchId;
            BranchName = branchName;

            ApplicationName = applicationName;
            ApplicationId = securityObject.GetApplicationId(applicationName, companyId);
            
        }
        public static bool ValidateUser(string username, string password){
            BCSecurity securityObject = new BCSecurity();
            BEUsuario.UsuarioDataTable usuario = securityObject.GetUserByName(username.Trim(), ApplicationId);
            if (usuario.Count == 0)
                return false;
            else 
            {
                return (password.Trim() == BCSecurity.Desencripta(usuario[0].lit_usuario_password));
            }
        }
        #endregion
    }
}
